import { queryDictData } from "@/api/house";
import { onMounted, ref } from 'vue'
export const useDictDataOptions = (dictType = ['REGION', 'SOURCE', 'PURPOSE', 'ROOMTYPE', 'HOUSINGSTAUTS', 'TYPE',
	'STATE'
]) => {
	const DeFindOptionsText: any = {
		// 状态
		state: {
			NEWLY_BUILT: '新筑',
			SECOND_HAND: '二手',
			EXPIRED_PROPERTY: '期房'
		},
		// 类型
		type: {
			APARTMENT: '公寓',
			ONE_HOUSEHOLD: '一户建',
			WHOLE_BUILDING: '整栋',
			LAND: '土地'
		},
		// 房屋现状
		housingStatus: {
			EMPTY_ROOM: '空室',
			LIVING_IN: '居住中',
			RENTING_OUT: '出租中'
		},
		// 房盘类型
		roomType: {
			PUBLIC_DISK: '公开盘',
			WATER_BOTTOM_PLATE: '水下盘'
		},
		// 用途
		purpose: {
			SELF_OCCUPATION: '自住',
			INVEST: '投资'
		},
		// 来源
		source: {
			SECOND_HAND: '二手',
			PROJECT_PARTY: '项目方',
			OTHER: '其他'
		},
		region: {
			JAPAN: '日本',
			GREECE: '希腊',
			BRITAIN: '英国',
			OTHER: '其他'
		}
	}
	/* 区域 */
	const regionOptions = ref<any>([])
	const getRegion = async () => {
		const res = await queryDictData({ dictType: 'REGION' });
		regionOptions.value = res.data

	}
	/* 来源 */
	const sourceOptions = ref<any>([])
	const getSource = async () => {
		const res = await queryDictData({ dictType: 'SOURCE' });
		sourceOptions.value = res.data

	}
	/* 用途 */
	const purposeOptions = ref<any>([])
	const getPurpose = async () => {
		const res = await queryDictData({ dictType: 'PURPOSE' });
		purposeOptions.value = res.data

	}
	/* 房盘类型 */
	const roomTypeOptions = ref<any>([])
	const getRoomType = async () => {
		const res = await queryDictData({ dictType: 'ROOM_TYPE' });
		roomTypeOptions.value = res.data

	}
	/* 房屋现状 */
	const housingStatusOptions = ref<any>([])
	const getHousingStatus = async () => {
		const res = await queryDictData({ dictType: 'HOUSING_STATUS' });
		housingStatusOptions.value = res.data

	}
	/* 类型 */
	const typeOptions = ref<any>([])
	const getType = async () => {
		const res = await queryDictData({ dictType: 'TYPE' });
		typeOptions.value = res.data

	}
	/* 状态 */
	const stateOptions = ref<any>([])
	const getState = async () => {
		const res = await queryDictData({ dictType: 'STATE' });
		stateOptions.value = res.data

	}
	const getOptionsText = (type: string, key: string) => {
		return DeFindOptionsText[type][key]
	}
	/* 初始化 */
	onMounted(() => {
		const map: any = {
			REGION: getRegion,
			SOURCE: getSource,
			PURPOSE: getPurpose,
			ROOMTYPE: getRoomType,
			HOUSINGSTAUTS: getHousingStatus,
			TYPE: getType,
			STATE: getState
		}
		setTimeout(() => {
			dictType.forEach((item: string) => {
				map[item]();
			})
		}, 500)

	})
	return { regionOptions, sourceOptions, purposeOptions, roomTypeOptions, typeOptions, stateOptions, housingStatusOptions, getHousingStatus, getOptionsText, }
}
